<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<%--
  Created by IntelliJ IDEA.
  User: 18134216985
  Date: 2024-04-08
  Time: 18:43
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>

<head>
    <script src="/webjars/layui/2.6.8/layui.js"></script>
    <link rel="stylesheet" href="/webjars/layui/2.6.8/css/layui.css">
    <title>Title</title>
</head>
<body>
<%--条件查询--%>
<div class="layui-collapse">
    <div class="layui-colla-item">
        <h2 class="layui-colla-title">查询条件</h2>
        <div class="layui-colla-content layui-show">

            <div class="layui-form"  id="searchForm" lay-filter="searchForm">
                <div class="layui-inline">
                    <input name="repairsType" class="layui-input" placeholder="维修类型">
                </div>
                <div class="layui-inline">
                    <input name="position" class="layui-input" placeholder="维修位置">
                </div>
                <div class="layui-inline">
                    <select name="plotid">
                        <option value="0">请选择小区</option>
                    </select>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn" onclick="search()" >查询</button>
                </div>

            </div>
        </div>
    </div>
</div>
<%--派单页面--%>
<div id="paidan" style="display:none;padding:20px">
    <form class="layui-form" id="paidanForm" lay-filter="paidanForm">
        <input type="hidden" name="id"/>
        <input type="hidden" name="plotid">
        <div class="layui-form-item">
            <label class="layui-form-label">报修位置:</label>
            <div class="layui-input-block">
                <input type="text" name="position" required  class="layui-input">
            </div>
        </div>
    <div class="layui-form-item">
            <label class="layui-form-label">报修类型:</label>
            <div class="layui-input-block">
                <input type="text" name="repairtype" class="layui-input">

            </div>
        </div>

          <div class="layui-form-item">
            <label class="layui-form-label">报修人:</label>
            <div class="layui-input-block">
                <input type="text" name="repairpeople"   class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">手机:</label>
            <div class="layui-input-block">
                <input type="text" name="phone"   class="layui-input">
            </div>
        </div>
          <div class="layui-form-item">
            <label class="layui-form-label">预约时间:</label>
            <div class="layui-input-block">
                <input type="text" name="hopetime"class="layui-input" >
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">小区:</label>
            <div class="layui-input-block">
                <input type="text" id="plot" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">分配员工:</label>
            <div class="layui-input-block">
                <select name="employee" id="updateRole">
                    <option value="">请选择员工</option>
                </select>
            </div>
        </div>
        <input type="hidden" name="repstateid" value="2">
    </form>
</div>

<table class="layui-hide" id="ID-table-demo-data" lay-filter="itemTable"></table>
<script>
    let table = layui.table;
    let laydate = layui.laydate;
    let $=layui.$;
    laydate.render({
        elem : "[name=hopetime]",
        type:'datetime',
        fullPanel:true
    });
    layui.use(["table","laydate"],function (){
        table.render({
            id:'leaders',
            elem:'#ID-table-demo-data',
            url:"/Repairs/selectAllRepairs",
            page:true,
            cols:[[
                {field:'number',align: 'center',type:'numbers',title:"编号"},
                {align: 'center',field:'id',hide:true,title:'编号'},
                {align: 'center',field: 'position',title: '报修位置'},
                {align: 'center',field: 'repairtype',title: '报修描述'},
                {align: 'center',field: 'repairpeople',title: '报修人'},
                {align: 'center',field: 'phone',title: '联系电话'},
                {align: 'center',field: 'plotname',title: '小区名称',templet(d) {
                        return d.plot==null?"-":d.plot.plotname
                    }},
                {align: 'center',field: 'hopetime',title: '预约时间'},
                {align: 'center',field: 'img',title: '照片',templet(d) {
                        return  d.img==null?"-":"<img src='/"+d.img+"' width='50px'/>";
                    }},
                {align: 'center',field: 'money',title: '价格'},
                {align: 'center',field: 'istype',title: '报修类型',templet(d) {
                        return d.istype==1?"居家维修":"公共维修";
                    }},
                {align: 'center',field: 'repstateid',title: '报修状态',templet(d){
                        return d.repairstate == null ? "-" : d.repairstate.statename;
                    }},
                {align: 'center',title: '员工',templet(d) {
                        return d.user == null ? "-" : d.user.username;
                    }},
                {title: '操作',templet(d) {
                    if(d.repairstate.id==1){
                        return" <button class='layui-btn layui-btn-sm layui-btn-normal' lay-event='paidan'>派单</button>"
                    }else {
                        return "-";
                    }

                    }},
            ]]
        })

    })
    //点击查询
    function search(){
        var where=layui.form.val('searchForm');
        layui.table.reload('leaders', {
            page: {
                curr:1
            },
            where: where
        });
    }
    //监听行内事件
    table.on("tool(itemTable)",function (obj){
       if(obj.event=="paidan"){
           paidan(obj);
       }
    })
    /***
     * 渲染下拉列表
     */
    $.get("/property/plot/show")
        .then(({data})=>{
            //data:数组
            $(data).each(function (i,e){
                let option = $("<option value='"+e.id+"'>"+e.plotname+"</option>");
                $("[name=plotid]").append(option);
            });
            //重新渲染下拉列表
            layui.form.render('select');
        });
    function paidan(obj){
        layui.form.val('paidanForm',obj.data)
        $("#plot").val(obj.data.plot.plotname)
        $("[name=plotid]").val(obj.data.plot.id)
        $("[name=employee]").empty()
        $.get("/Users/selectUserByPlotid?plotid="+obj.data.plot.id).then(({data})=>{
            $(data).each(function (i,e){
                let option = $("<option value='"+e.id+"'>"+e.username+"</option>");
                $("[name=employee]").append(option);
            });
            layui.form.render('select');

        })
        $("[name=repstateid]").val(2)
        layui.layer.open({
            type:1,
            area:["450px","500px"],
            title:"分派任务",
            content:$("#paidan"),
            btn:["确定","取消"],
            yes(){
                let updateForm=layui.form.val("paidanForm");
                $.post("/Repairs/updateRepairs",updateForm).then(({msg})=>{
                    layui.layer.close(layui.layer.index);
                    layui.layer.msg(msg);
                    layui.table.reload("leaders");
                })
            }
        })
    }
</script>
</body>
</html>
